package tr.gov.tubitak.bilgem.esya.certviewer.viwerasn;

import sun.security.x509.Extension;
import tr.gov.tubitak.bilgem.esya.certviewer.EByteTools;

/**
 * Created by IntelliJ IDEA.
 * User: ramazan.girgin
 * Date: 12/4/11
 * Time: 4:46 PM
 * To change this template use File | Settings | File Templates.
 */
public class EUnknownExtension implements ECertExtension{
    String oid;
    byte [] value;

    Extension extension=null;

    public EUnknownExtension()
    {

    }
    public EUnknownExtension(String oid, byte[] value) {
        this.oid = oid;
        this.value = value;
    }

    @Override
    public String getName() {
        if(extension != null)
        {
            return extension.getClass()+"("+extension.getExtensionId().toString()+")";
        }
        else
        return oid;
    }

    @Override
    public String getShortTitle() {
         if(extension != null)
        {
          return  EByteTools.toHexString(extension.getExtensionValue()," ");
        }
        else
         {
            return EByteTools.toHexString(value," ");
         }
    }

    @Override
    public String getLongTitle() {
        return getShortTitle();
    }

    @Override
    public boolean isCritical() {
        if(extension != null)
        {
            return extension.isCritical();
        }
        return false;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public void encode(byte[] data) {
        value = data;
        //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public void setAsnObject(Object asnObject) {
        if(asnObject instanceof Extension)
        {
            extension = (Extension) asnObject;
        }
    }
}
